package com.server.common.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

// Result.java用于封装ResultCode.java
// 返回信息全部被封装为Result对象
// 如果是单独的类对象，则直接封装到Result.data中返回
// 如果涉及到分页，则通过PageResult配置到Result.data中

/**
 * 数据响应对象
 * json格式数据
 * {
 *      boolean success:"",     //是否成功
 *      Integer code:"",        //返回码
 *      String message:"",      //返回信息
 *      Object data:{           //返回数据
 *          data字段
 *      }
 * }
 */
@Data
@NoArgsConstructor
public class Result {

    //private boolean success;//是否成功
    private Integer code;// 返回码
    private String message;//返回信息
    private Object data;// 返回数据

    public Result(ResultCode code) {
        //this.success = code.success;
        this.code = code.code;
        this.message = code.message;
    }

    public Result(ResultCode code,Object data) {
        //this.success = code.success;
        this.code = code.code;
        this.message = code.message;
        this.data = data;
    }

    public Result(Integer code,String message,boolean success) {
        this.code = code;
        this.message = message;
        //this.success = success;
    }

    public static Result SUCCESS(){
        return new Result(ResultCode.SUCCESS);
    }

    public static Result ERROR(){
        return new Result(ResultCode.SERVER_ERROR);
    }

    public static Result FAIL(){
        return new Result(ResultCode.FAIL);
    }
}